<template>
	<div class="wpsz">
		<div class="all">
			<div class="wpszlt">
				<div class="wpfl">
					<span>课程</span>
					<el-select v-model="vkcid1" placeholder="请选择课程" @change="getxzjclist(vkcid1)">
						<el-option v-for="v in xzkclist" :label="v.mc" :value="v.id+''"></el-option>
					</el-select>
				</div>
			</div>
			<div class="wpszlt1">
				<el-collapse v-model="activeName" accordion v-for='(v,index) in datalistto'>
					<el-collapse-item style="text-align: center;" :title="v.groupkey" :name='index'>
						<div v-for='i in xzjcdataList' v-if="v.groupkey == i.groupkey ? (i.id!='-99' ? true : false) : false" :class="i.groupkey">
							<div :class="i.classname" @click="wpfxbtnclickjc(i.id)">{{i.mc}}</div>
						</div>
					</el-collapse-item>
				</el-collapse>
				<!--<div v-for='v in datalistto' :class="v.groupkey" style="width: 100%; height: 40px; border-bottom: 1px solid #CCCCCC;">
					<div class="jclt" @click="wpfxbtnclickjc(v.id)">{{v.mc}}</div>
				</div>-->
			</div>
		</div>
		<div class="index-page">
			<!-- 顶部按钮 -->
			<div class="but1">
				<router-link to="/home">
					<el-button type="warning" size="small" style='margin-right: 5px;' icon="el-icon-menu">首页</el-button>
				</router-link>
				<!--<el-button type="success" size="small" class="add btn" @click='componentsShow("add")' icon="el-icon-edit">发起老师评价</el-button>-->
				<el-button type="danger" size="small" :disabled="multipleDeleteDisabled" icon="delete" @click="componentsShow('plwp')">批量布置作业</el-button>
			</div>

			<!-- 模糊搜索条件 -->
			<div class="search">
				<div class="search-item">
					<!--<el-input v-model="vjcmc" placeholder="请选择教材名称 " :readonly="true"  class="code-search"  icon="add" ></el-input>
					<el-button size="small" @click="showwp()" style='background: #409EFF;color: white;' >选择</el-button> -->
					<!--<el-button type="primary" class="add btn" style="border-radius:13px;" :loading="searchLoading" @click="search" icon="el-icon-search"></el-button>-->

				</div>
			</div>
			<!-- 数据表格展示区域 -->
			<el-table :data="dataList" border stripe size="small" align="left" class="admin-table" @select="checkSelect" @select-all="checkall">
				<el-table-column type="selection" width="35"></el-table-column>
				<div slot='empty'>
					<img src="../../../assets/img/empty.png" style="width:40px;vertical-align: middle;">
					<span style="vertical-align: middle;">暂时还没有内容哦!</span>
				</div>
				<el-table-column :prop="v.prop" :label="v.label" v-for="(v,index) in portTitleList" align="center" show-overflow-tooltip v-if="v.hide != 0" :formatter="v.formatter" :align="v.align || 'center'" :fixed="v.fixed" :class-name="v.columnStyle" :width="v.width" :min-width="v.minWidth" :header-align="v.headerAlign || 'center'">
					<template scope="scope">
						<div slot="reference" :style="tableCellControl(scope)">
							{{ scope.row[scope.column.property] }}
						</div>
					</template>
				</el-table-column>
				<!-- <el-table-column label="操作" width="160" align="center"> -->
				<el-table-column fixed="right" align="center" label="操作" width="170px">
					<template scope="scope">
						<!-- v-if="scope.row.qx == 'Y'"-->
						<el-button size="mini" type="success" @click="componentsShow('info',scope)">详情</el-button>
						<el-button size="mini" type="warning" @click="componentsShow('edit',scope)">修改</el-button>
					</template>
				</el-table-column>
			</el-table>

			<!-- 分页查询区域 -->
			<!--<el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page.sync="pageindex"
            :page-sizes="pagesizes"
            :page-size="pagesize"
            :layout="layout"
            :total="total"
            class="class-page">
        </el-pagination>-->

			<!-- 各个组件显示区域 -->
			<Kschoose class="wpfl" @wpchoose="wpchooseed" @close="wpchoosecancel" v-if="showchoselist"></Kschoose>

			<!-- 编辑组件 -->
			<AddComponent v-if="portComponents.add.toggle" @close="componentsHide"></AddComponent>
			<!-- 编辑组件 -->
			<EditComponent v-if="portComponents.edit.toggle" @close="componentsHide" :params="{list:portComponents.info.params,id:this.gdid}"></EditComponent>
			<!-- info组件 -->
			<infoComponent v-if="portComponents.info.toggle" @close="componentsHide" :params="{list:portComponents.info.params,id:this.gdid}"></infoComponent>
			<PlwpComponent v-if="portComponents.plwp.toggle" @close="componentsHide" :params="{list:this.multipleDelNum,id:this.gdid}"></PlwpComponent>

			<!-- 单独删除组件 -->
			<DeleteComponent v-if="portComponents.singleDelete.toggle" @close="componentsHide" :data="portComponents.singleDelete.data"></DeleteComponent>
			<!-- 批量删除组件 -->
			<DeleteComponent v-if="portComponents.multipleDelete.toggle" @close="componentsHide" :data="portComponents.multipleDelete.data"></DeleteComponent>
			<!-- 子路由显示区域 -->
			<router-view class="port-view"></router-view>
		</div>
	</div>
</template>

<script>
	import Vue from 'vue'
	import AddComponent from './add'
	import EditComponent from './edit'
	import InfoComponent from './info'
	import PlwpComponent from './plwp'
	import DeleteComponent from './del'
	import Kschoose from '../../manage/kssz/kschoose'
	import qs from 'qs'
	export default {
		components: {
			DeleteComponent,
			AddComponent,
			EditComponent,
			Kschoose,
			PlwpComponent,
			InfoComponent
		},
		data() {
			return {
				gdid:'',
				activeName: 0,
				multipleDeleteDisabled: true,
				type: '',
				vlsid: '',
				vjcid: '',
				multipleDelNum: '',
				activeNames: ['1'],
				xzjcdataList: [],
				showchoselist: false,
				vjcmc: '',
				vkcid1: '',
				xzkclist: '',
				//				vkcid:'',
				comboxlist: [],
				/*组件区域*/
				portComponents: {
					singleDelete: {
						type: 'singleDelete',
						toggle: false,
						params: '',
						data: {
							index: '',
							type: 'single',
							title: '此操作将删除该条数据, 是否继续?'
						}
					},
					multipleDelete: {
						type: 'multipleDelete',
						toggle: false,
						params: '',
						data: {
							index: '',
							type: 'multiple',
							title: '此操作将删除您选中的数据, 是否继续?'
						}
					},
					plwp: {
						type: 'plwp',
						toggle: false,
						params: '',
						data: {}
					},
					add: {
						type: 'add',
						toggle: false,
						params: '',
						data: {}
					},
					edit: {
						type: 'edit',
						toggle: false,
						params: '',
						data: {}
					},
					info: {
						type: 'info',
						toggle: false,
						params: '',
						data: {}
					}

				},

				multipleDelNum: '', //获取批量选择的数据
				dataList: [], //表格数据

				/*
				    prop :  接口参数名
				    label : 接口中文名
				    hide : 是否隐藏这一列   0是隐藏  1是显示
				    align : 这一列对齐顺序 ： left,right,center
				    headerAlign : 这一列表头对齐方式 ： left,right,center
				    formatter: function (row, column) {}
				*/
				portTitleList: [{
						prop: 'id',
						label: '作业id',
						hide: 0,
						align: 'center',
						fixed: false,
						width: '',
						minWidth: '',
						headerAlign: 'center'
					},
					{
						prop: 'jcid',
						label: '教材id',
						hide: 0,
						align: 'center',
						fixed: false,
						width: '',
						minWidth: '',
						headerAlign: 'center'
					},
					{
						prop: 'kcmc',
						label: '课程名称',
						hide: 1,
						align: 'center',
						fixed: false,
						width: '120',
						minWidth: '',
						headerAlign: 'center'
					},
					{
						prop: 'jcmc',
						label: '教材名称',
						hide: 1,
						align: 'center',
						fixed: false,
						width: '120',
						minWidth: '',
						headerAlign: 'center'
					},
					{
						prop: 'day',
						label: 'day',
						hide: 1,
						align: 'center',
						fixed: false,
						width: '80',
						minWidth: '',
						headerAlign: 'center'
					},
					{
						prop: 'nr',
						label: '作业内容',
						hide: 1,
						align: 'center',
						fixed: false,
						width: '',
						minWidth: '',
						headerAlign: 'center'
					}

				],
				datalistto: [],
				datalistli: [],
				/*动画加载*/
				isLoading: false, //动画加载
				searchLoading: false, //搜索按钮触发按钮动画

				/*模糊搜索条件*/

				/*分页属性设置*/
				layout: 'total, sizes, prev, pager, next, jumper', //组件布局
				pageindex: 1, //当前分页页码
				pagesizes: [12, 24, 36, 72], //显示个数的选择器选项
				pagesize: 12, //每页显示条目数
				total: 0, //总条数

				dropDownData: '', //
			}
		},
		created() {

			//加载页面时调用
			this.$store.dispatch('changeTitle', '作业设置'); //修改title
			this.$store.dispatch('changeRouterIndex', '/admin/bjjczy'); //修改路由
			this.getxzkclist();
			this.getcomboxlist(); //获取下拉框数据

		},
		methods: {
			wpfxbtnclickjc(jcid) {
				for(var i in this.xzjcdataList) {
					if(this.xzjcdataList[i].id == jcid) {
						this.xzjcdataList[i].classname = 'jc2'
					} else {
						this.xzjcdataList[i].classname = 'jc'
					}
				}
				this.vjcid = jcid;
				//				this.setrowselected();
				this.search(jcid);
			},

			getxzkclist() {
				var logininfo = JSON.parse(localStorage.logininfo);
				this.searchLoading = true;
				var params2 = qs.stringify({
					yhid: logininfo.id,
					xxid: logininfo.xxid
				})
				//执行
				this.axios.post(this.$store.state.api + 'kcfl/getfllist', params2)
					.then(res => {
						//						console.log(res, 11)
						this.xzkclist = res.data.data.list;
						var vkcid1 = this.xzkclist[0].id
						this.getxzjclist(vkcid1)
						this.vkcid1 = this.xzkclist[0].id + ''
					}).catch(res => {
						//						console.log(res)
					})
			},
			getxzjclist(vkcid1) { //查询搜索触发事件
				this.datalistto = []
				var logininfo = JSON.parse(localStorage.logininfo); //获取学校  用户id
				var params3 = qs.stringify({
					fxkcid: vkcid1,
					yhid: logininfo.id,
					xxid: logininfo.xxid
				});
				this.searchLoading = true;
				this.axios.post(this.$store.state.api + 'kcfl/getwpjclist1', params3)
					.then(res => {
						console.log('111', res)
						this.isLoading = false; //动画结束
						// let data = res.data.data;
						// let list = data.list1;
						// let list2 = data.list2;
						// let list3 = data.list3;
						// let list4 = data.list4;
						// let list5 = data.list5;
						// this.total = data.totalPage;
						this.xzjcdataList = res.data.data.list;
						for(var i in this.xzjcdataList) {
							if(this.xzjcdataList[i].id == '-99') {
								this.datalistto.push(this.xzjcdataList[i])
							}
						}
						var ad = []
						for(var i in this.xzjcdataList) {
							if(this.xzjcdataList[i].groupkey == this.datalistto[0].mc) {
								ad.push(this.xzjcdataList[i])
							}
						}
						this.wpfxbtnclickjc(ad[1].id); //分页获取默认数据
						this.searchLoading = false;
					}).catch(res => {
						//						console.log(res)
						this.searchLoading = false;
					})
			},
			showwp() {
				this.showchoselist = true;
			},
			wpchooseed(josndata) {
				this.vfxkcidmc = josndata.kcmc;
				this.vfxkcid = josndata.fxkcid;
				this.vkssl = josndata.kssl;
				this.showchoselist = false;
			},
			wpchoosecancel(setting) {
				//				console.log(setting,111133)
				if(setting.cancel == false) {
					this.vjcmc = setting.data[0].mc;
					this.vjcid = setting.data[0].id;
					// this.vfxkcid = setting.data[0].id;
					// this.vfxkcidmc = setting.data[0].mc;
					// this.vjcidmc = setting.data[0].cmc;
					// this.vjcid = setting.data[0].jcid;
					// this.vcid = setting.data[0].cid;
					// this.vkssl = setting.data[0].number;

				}

				this.showchoselist = false;
//				this.search();
			},
			cancelf() {
				this.$store.dispatch('changeTitle', '首页'); //修改title
			},
			search(jcid) { //查询搜索触发事件
				var logininfo = JSON.parse(localStorage.logininfo);
				this.searchLoading = true;
				var params2 = qs.stringify({
					jcid: jcid,
					yhid: logininfo.id,
					xxid: logininfo.xxid,
				})
				//执行
				this.axios.post(this.$store.state.api + 'bjjczymodel/getlist', params2)
					.then(res => {
						console.log(res, 'kkkkkkkk')
						let data = res.data.data;
						let list = data.list;
						this.total = data.totalPage;
						this.dataList = list;
						this.gdid = jcid
						this.searchLoading = false;
					}).catch(res => {
						this.searchLoading = false;
					})
			},
			getcomboxlist() {
				var logininfo = JSON.parse(localStorage.logininfo);
				var params2 = qs.stringify({
					yhid: logininfo.id,
					xxid: logininfo.xxid
				})
				//执行
				this.axios.post(this.$store.state.api + 'xspjlsmb/getmc', params2)
					.then(res => {
						let data = res.data.data;
						let list = data.list;
						this.comboxlist = list;
					}).catch(res => {})
			},
			tableCellControl(scope) {
				//表格单元格控制CSS样式
				/*  if (scope.row.id == 112 && scope.column.property == "iname") {
				      return {
				          color:"red",
				      }
				  }else{
				      return {
				          color:"green",
				      }
				  }*/
			},
			handleSizeChange(val) { //每页显示条数触发事件
				this.pagesize = val;
				this.pageindex = 1;
//				this.search();
			},

			handleCurrentChange(val) { //分页触发事件
//				this.search();
			},
			checkSelect(selection, row) { //点击单选select触发事件
				this.multipleDelNum = selection
				if(this.multipleDelNum.length > 0) {
					this.multipleDeleteDisabled = false
				} else {
					this.multipleDeleteDisabled = true
				}
			},
			checkall(selection) { //点击全选select触发事件
				this.multipleDelNum = selection
				if(this.multipleDelNum.length > 0) {
					this.multipleDeleteDisabled = false
				} else {
					this.multipleDeleteDisabled = true
				}
			},
			/* 组件的弹框  */
			componentsShow(type, data) { //显示组件
				for(let i in this.portComponents) {
					if(type == this.portComponents[i].type) {

						this.portComponents[i].toggle = true;
						this.portComponents[i].params = data;

						if(this.portComponents[i].data.type == 'single') {
							this.portComponents[i].data.index = data.row.id

						} else if(this.portComponents[i].data.type == 'multiple') {
							this.portComponents[i].data.index = this.multipleDelNum;

						} else if(this.portComponents[i].type == 'test') {
							this.portComponents[i].data.distinction = "test";

						} else if(this.portComponents[i].type == 'score') {
							this.portComponents[i].data.distinction = "score";

						} else {
							return;
						}
						return;
					}
				}

			},
			componentsHide(setting) { //关闭组件
				if(setting.id){
					this.search(setting.id);
				}
				this.multipleDeleteDisabled = true
				for(let i in this.portComponents) {
					if(setting.type == this.portComponents[i].type) {
						this.portComponents[i].toggle = false;

						if(!setting.cancel) {
							this.search();
						}
						return;
					}
				}
			}
		},
		computed: {
			//          multipleDeleteDisabled () {
			//              if (this.multipleDelNum) {
			//                  return false;
			//              }else{
			//                  return true
			//              }
			//          }
		}
	}
</script>

<style lang="less" scoped>
	.wpsz {
		font-size: 12px;
		position: relative;
		.all {
			float: left;
			font-size: 12px;
			width: 20%;
			height: 100%;
			/*border: 1px solid #CCCCCC;*/
			/*margin-right: 10px;*/
		}
		.wpszlt {
			float: left;
			font-size: 12px;
			width: 100%;
			height: 100%;
			/*border: 1px solid #CCCCCC;*/
			/*margin-right: 10px;*/
		}
		.wpszlt1 {
			float: left;
			font-size: 12px;
			width: 100%;
			height: 100%;
			/*border: 1px solid #CCCCCC;*/
			/*margin-right: 10px;*/
		}
		.wpfl {
			width: 100%;
			height: 40px;
			float: left;
			background: #58A9FC;
			color: white;
			font-size: 16px;
			line-height: 40px;
			border: 1px solid #CCCCCC;
		}
		.jc:hover {
			background: #9FC9F9;
		}
		.jc {
			width: 100%;
			height: 40px;
			/*color: #2E2F2F;*/
			float: left;
			text-align: center;
			line-height: 40px;
			font-size: 12px;
			/*border: 1px solid #CCCCCC;*/
			cursor: pointer;
		}
		.jc2 {
			width: 100%;
			height: 40px;
			line-height: 40px;
			float: left;
			color: white;
			background: #71BFF4;
		}
		.index-page {
			font-size: 12px;
			width: 80%;
			float: right;
			border-left: 1px solid #CCCCCC;
			.btn {
				height: 30px;
				padding: 0 10px;
			}
			.but1 {
				width: 23%;
				margin-top: 8px;
				float: left;
			}
			.search {
				width: 77%;
				float: right;
				text-align: right;
			}
			.classInfo:hover {
				color: #4094c7;
				cursor: pointer;
				text-decoration: underline;
			}
			.code-search {
				height: 30px;
				margin: 10px 0 10px 0;
				min-width: 100px;
				max-width: 135px;
			}
			.change-time {
				width: 480px;
				display: inline-block;
			}
			.class-page {
				text-align: left;
				margin-top: 10px;
			}
			.search-item {
				display: inline-block;
				margin-right: 10px;
			}
			h2 {
				line-height: 40px;
			}
			.el-button+.el-button {
				margin-left: 0px;
			}
		}
	}
</style>